package com.XiGuaXiaoMe.controller.tea;

import com.XiGuaXiaoMe.dao.userDao;
import com.XiGuaXiaoMe.entity.Users;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

public class TeacherAddServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String password,email;
        String userName;
        userDao dao=new userDao();
        Users user=null;
        int result=0;
        PrintWriter out=null;
        //1、【调用请求对象】读取【请求头】参数信息，得到用户注册信息
       userName=req.getParameter("userName");
       password=req.getParameter("password");
       email=req.getParameter("email");
        //2、【调用UserDao】将用户信息填充到INSERT命令并借助JDBC规范发送到数据库服务器
        user=new Users(null,userName,password,email);
        result=dao.add(user);
        //3、【调用响应对象】将【处理结果】以二进制形式写入到响应体中
        resp.setContentType("text/html;charset=utf-8");
        out=resp.getWriter();
        if(result==1)
        {
            out.print("<font style='color:red;font-size:40px'>用户信息注册成功</font>");
        }else{
            out.print("<font style='color:red;font-size:40px'>用户信息注册失败</font>");

        }
    }
    //Tomcat负责销毁【请求对象】和【响应对象】
    //Tomcat负责将Http响应协议包推送到发送到发起请求的浏览器上
    //浏览器根据响应头content-type指定编译器对响应体二进制内容编辑
    //浏览器将编辑后结果在窗口中展示给用户【结束】
}
